package com.treasure.mall.biz.repository.live;

import com.treasure.mall.biz.base.JpaSearchableRepository;
import com.treasure.mall.biz.entity.live.LiveSessionPO;
import com.treasure.mall.zbq.common.ienum.live.LiveEnums;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.biz.repository.live
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/6/11 20:06
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 * Copyright 2019-2022 com.treasure.mall.biz.repository.live Inc. All rights reserved.
 */
@Repository
public interface LiveSessionRepository extends JpaSearchableRepository<LiveSessionPO, String> {
    List<LiveSessionPO> findByLiveRoomPO_IdAndPlayStatus(Long roomId, LiveEnums.PlayStatus playStatus);

    LiveSessionPO findTopByLiveRoomPO_IdAndPlayStatusOrderByForeshowTimeAsc(Long roomId, LiveEnums.PlayStatus playStatus);

    LiveSessionPO findTopByLiveRoomPO_IdAndPlayStatusIsNotOrderByStartTimeDesc(Long roomId, LiveEnums.PlayStatus playStatus);


    /**
     * 开启机器人
     *
     * @param id
     * @param enable
     */
    @Query("update LiveSessionPO s set s.enableRobot=?2 where s.id=?1")
    @Modifying
    @Transactional
    void enableRobot(String id, Boolean enable);

    List<LiveSessionPO> findByPlayStatus(LiveEnums.PlayStatus playStatus);

}
